home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / COMM / RPL60 / RPLLOW.INC < prev    next >
Text File  |  1992-12-31  |  9KB  |  301 lines

  1.  
  2.   {*}
  3.   {*source code copyright (c) 1985, by TurboPower Software*}
  4.   {*}
  5.   {*}
  6.  
  7.   procedure Wr(s : String);
  8.     {-shell around Wr to cut memory size}
  9.   begin
  10.     Write(s);
  11.   end;
  12.  
  13.   procedure WrL(s : String);
  14.     {-shell around WrL to cut memory size}
  15.   begin
  16.     WriteLn(s);
  17.   end;
  18.  
  19.   procedure HiVid;
  20.     {-intensify the current entryattribute}
  21.   begin
  22.     if CurrentMode = Mono then
  23.       TextColor(HighMono)
  24.     else
  25.       TextColor(HighColor);
  26.   end;                            {hivid}
  27.  
  28.   procedure LoVid;
  29.     {-deintensify the current entryattribute}
  30.   begin
  31.     if CurrentMode = Mono then
  32.       TextColor(LowMono)
  33.     else
  34.       TextColor(LowColor);
  35.   end;                            {lovid}
  36.  
  37.  
  38.   procedure Halt;
  39.     {-replace Turbo Halt procedure with a return code version}
  40.   begin
  41.     System.Halt(1);
  42.   end;                            {halt}
  43.  
  44.   procedure DefaultExtension(Extension : FileString; var InFile : FileString);
  45.     {-assign a default extension to a DOS 2.0+ pathname}
  46.     {extension should be a maximum of 3 characters, and does not include dot}
  47.   var
  48.     i              : Integer;
  49.     Temp           : FileString;
  50.   begin
  51.     i := Pos('..', InFile);
  52.     if i = 0 then
  53.       Temp := InFile
  54.     else
  55.       {a pathname starting with ..}
  56.       Temp := Copy(InFile, i+2, 64);
  57.     i := Pos('.', Temp);
  58.     if i = 0 then InFile := InFile+'.'+Extension;
  59.   end;                            {defaultextension}
  60.  
  61.   procedure OpenFile(fName : FileString; var Handle : Integer);
  62.     {-open a file for reading and return the handle}
  63.   begin
  64.     fName := fName+Null;
  65.     Reg.ds := Seg(fName[1]);
  66.     Reg.dx := Ofs(fName[1]);
  67.     Reg.ax := $3D00;              {open for reading}
  68.     Reg.flags := 0;
  69.     MsDos(Dos.Registers(Reg));
  70.     if (Reg.flags and 1) = 1 then begin
  71.       WrL('problem opening '+fName);
  72.       Halt;
  73.     end;
  74.     Handle := Reg.ax;
  75.   end;                            {openfile}
  76.  
  77.   procedure ForceDup(Handle, NewHandle : Integer);
  78.     {-force a dup to the newhandle number}
  79.   begin
  80.     Reg.bx := Handle;
  81.     Reg.cx := NewHandle;
  82.     Reg.ax := $4600;
  83.     MsDos(Dos.Registers(Reg));
  84.   end;                            {forcedup}
  85.  
  86.   function GetChunk(var l : BufLine; var Count : Integer) : Boolean;
  87.     {-read a chunk of characters from the standard input}
  88.     {return true if EOF reached}
  89.   begin
  90.     Reg.bx := InHandle;           {standard input device}
  91.     Reg.cx := LabLen;
  92.     Reg.ds := Seg(l[1]);
  93.     Reg.dx := Ofs(l[1]);
  94.     Reg.ax := $3F00;
  95.     MsDos(Dos.Registers(Reg));
  96.     Count := Reg.ax;
  97.       if Count < LabLen then GetChunk := True else GetChunk := False;
  98.   end;                            {getchunk}
  99.  
  100.   procedure CreateFile(fName : FileString; var Handle : Integer);
  101.     {-create or rewrite a file and return the handle}
  102.   begin
  103.     fName := fName+Null;
  104.     Reg.ds := Seg(fName[1]);
  105.     Reg.dx := Ofs(fName[1]);
  106.     Reg.cx := 0;                  {normal file}
  107.     Reg.ax := $3C00;
  108.     Reg.flags := 0;
  109.     MsDos(Dos.Registers(Reg));
  110.     if (Reg.flags and 1) = 1 then begin
  111.       WrL('problem opening '+fName);
  112.       Halt;
  113.     end;
  114.     Handle := Reg.ax;
  115.   end;                            {createfile}
  116.  
  117.   procedure CloseFile(Handle : Integer);
  118.     {-close a file opened by openfile}
  119.   begin
  120.     Reg.bx := Handle;
  121.     Reg.ax := $3E00;
  122.     Reg.flags := 0;
  123.     MsDos(Dos.Registers(Reg));
  124.     if (Reg.flags and 1) = 1 then begin
  125.       WrL('problem closing file');
  126.       Halt;
  127.     end;
  128.   end;                            {closefile}
  129.  
  130.   function IoStat(Bit : Integer) : Boolean;
  131.     {-check status of the standard I/O}
  132.     {bit=0 for input, 1 for output}
  133.     {returns true if I/O is through console}
  134.   var
  135.     Temp0, Temp1   : Boolean;
  136.   begin
  137.     Reg.ax := $4400;
  138.     Reg.bx := Bit;                {standard input or output}
  139.     MsDos(Dos.Registers(Reg));
  140.     Temp0 := (Reg.dx and 128) <> 0;
  141.     Temp1 := (Reg.dx and (1 shl Bit)) <> 0;
  142.     IoStat := Temp0 and Temp1;
  143.   end;                            {iostat}
  144.  
  145.   procedure AppendS(var l1; Len1 : Integer; var l2; Len2 : Integer; var lOut : Line);
  146.     {-append character object l2 to end of l1, output onto lout}
  147.     {-using untyped parameters so that l1,l2 can be either strings or "lines"}
  148.     {use a temp output to avoid problems when input strings are same as output}
  149.   var
  150.     Temp           : Line;
  151.     RemLen         : Integer;
  152.   begin
  153.     {check for overflow length}
  154.     if Len1 < LabLen then begin
  155.       RemLen := LabLen-Len1;
  156.       if Len2 > RemLen then Len2 := RemLen;
  157.       {put first string onto temp}
  158.       Move(l1, Temp.Val[1], Len1);
  159.       {append 2nd string to temp}
  160.       Move(l2, Temp.Val[Len1+1], Len2);
  161.       {set length}
  162.       Temp.Length := Len1+Len2;
  163.     end else begin
  164.       {lout is just l1, no room for more}
  165.       Len1 := LabLen;
  166.       Move(l1, Temp.Val[1], Len1);
  167.       Temp.Length := Len1;
  168.     end;
  169.     {transfer onto lout}
  170.     lOut := Temp;
  171.   end;                            {appends}
  172.  
  173.   procedure CheckMore(var ScreenLine : Integer);
  174.     {-see if user wants to see more}
  175.     {call after each WrL statement}
  176.   var
  177.     c              : Char;
  178.     Stop           : Boolean;
  179.   begin
  180.     ScreenLine := ScreenLine+1;
  181.     if ScreenLine > 24 then begin
  182.       Stop := False;
  183.       Wr('....more?  ');
  184.       c := ReadKey;
  185.       if (c = ' ') or (UpCaseMac(c) = 'Y') then ScreenLine := 1
  186.       else if c = ^M then ScreenLine := ScreenLine-1
  187.       else Stop := True;
  188.       Wr(^H^H^H^H^H^H^H^H^H^H^H); ClrEol;
  189.       if Stop then Halt;
  190.     end;
  191.   end;                            {checkmore}
  192.  
  193.   procedure PutL(l : Line);
  194.     {-send a line to the standard output}
  195.   begin
  196.     if ShowLines then begin
  197.       Str(lNum:4, nStr);
  198.       nStr := nStr+'  ';
  199.       AppendS(nStr[1], Length(nStr), l.Val, l.Length, l);
  200.     end;
  201.     Reg.bx := OutHandle;
  202.     Reg.cx := l.Length;
  203.     Reg.ds := Seg(l.Val[1]);
  204.     Reg.dx := Ofs(l.Val[1]);
  205.     Reg.ax := $4000;
  206.     MsDos(Dos.Registers(Reg));
  207.     if (Reg.flags and 1) = 1 then begin
  208.       WrL('');
  209.       WrL('ERROR: cannot Wr to redirected output device....');
  210.       Halt;
  211.     end;
  212.     if Reg.ax <> l.Length then begin
  213.       WrL('');
  214.       WrL('insufficient disk space....');
  215.       Halt;
  216.     end;
  217.     if ConsoleOut then CheckMore(ScreenLine);
  218.   end;                            {putl}
  219.  
  220.   function ReadYesNo(Default : Boolean) : Boolean;
  221.     {-get the answer to a yes/no question and return true/false}
  222.   var
  223.     c              : Char;
  224.   begin
  225.     repeat
  226.       c := ReadKey;
  227.       c := UpCaseMac(c);
  228.     until (c in ['Y', 'N', ^M]);
  229.     if c = ^M then begin
  230.         if Default then c := 'Y' else c := 'N';
  231.     end;
  232.     WrL(c);
  233.     ReadYesNo := (c = 'Y');
  234.   end;                            {readyesno}
  235.  
  236.   function GetCom(UsePsp : Boolean; InLin : LongString; var ErrString : Message) : Boolean;
  237.     {-parse command line passed from DOS to Turbo Pascal}
  238.     {return false if error encountered}
  239.     {errstring will contain a text error message if getcom is false}
  240.   const
  241.     Delim          : set of Char = [' ', ^i];
  242.     Comm           = $80;         {offset of command tail in program segment prefix}
  243.   var
  244.     BufPos         : Byte;        {position in command line buffer}
  245.     TokPos         : Byte;        {position in current token}
  246.     nChars         : Byte;        {one more than the characters in the command tail}
  247.     c              : Char;
  248.     m1, m2         : Message;
  249.     Lin            : LongString;
  250.  
  251.     function ComChar : Char;
  252.       {-return the command character at current buffer position}
  253.     begin
  254.       ComChar := Lin[BufPos];
  255.       BufPos := BufPos+1;
  256.     end;                          {comchar}
  257.  
  258.   begin                           {getcom}
  259.     GetCom := True;
  260.     if UsePsp then begin
  261.       {define buffer stopping point}
  262.       Lin := String(Ptr(PrefixSeg, $80)^);
  263.       nChars := 1+Length(Lin);
  264.     end else begin
  265.       Lin := InLin;
  266.       nChars := 1+Length(Lin);
  267.     end;
  268.     BufPos := 1;
  269.     argc := 0;
  270.     if nChars > 1 then begin
  271.       c := ComChar;
  272.       while (c in Delim) do c := ComChar; {skip leading blanks}
  273.       while BufPos <= nChars do begin
  274.         if argc < MaxTok then begin {get the next argument}
  275.           argc := argc+1;
  276.           TokPos := 0;
  277.           while ((BufPos <= nChars) and (not(c in Delim))) do begin
  278.             if TokPos < TokLen then begin {read the argument}
  279.               TokPos := TokPos+1;
  280.               argv[argc][TokPos] := c;
  281.               c := ComChar;
  282.             end else begin        {set error and skip the rest}
  283.               GetCom := False;
  284.               Str(argc, m1);
  285.               Str(TokLen, m2);
  286.               ErrString := 'ERROR: argument# '+m1+' truncated to '+m2+' characters';
  287.               while (not(c in Delim)) do c := ComChar;
  288.             end;
  289.           end;
  290.           argv[argc][0] := Chr(TokPos); {store the arg length}
  291.           while (c in Delim) do c := ComChar; {skip blanks}
  292.         end else begin
  293.           GetCom := False;
  294.           Str(MaxTok, m1);
  295.           ErrString := 'ERROR: number of arguments truncated to '+m1;
  296.           BufPos := nChars+1;
  297.         end;
  298.       end;
  299.     end;
  300.   end;                            {getcom}
  301.